package com.xxx.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.xxx.dao.GameMapper;
import com.xxx.model.Game;
import com.xxx.utils.ResultUtil;
 
@RestController
@RequestMapping(value = "/operat")
public class GameController {
	
    @Autowired
    private GameMapper gameMapper;
 
    @RequestMapping(value = "/getGame/{id}",method = RequestMethod.GET)
    public Object getGame(@PathVariable int id) throws Exception{
    	Game game = gameMapper.selectByPrimaryKey(id);
    	if(game != null) {
    		return ResultUtil.success(game);
    	}else {
    		return ResultUtil.success("根据id获取到的数据为空，请确认传参！");
    	}
    }
    
    @RequestMapping(value = "/getGameList",method = RequestMethod.GET)
    public Object getGameList() throws Exception{
    	List<Game> gameList = gameMapper.getGameList();
    	if(gameList != null && gameList.size() > 0) {
    		return ResultUtil.success(gameList);
    	}else {
    		return ResultUtil.success("查询数据为空，请确认！");
    	}
    }
    
    @RequestMapping(value = "/insGame",method = RequestMethod.POST)
    public Object insGame(@RequestBody Game game) throws Exception{
    	int retule = gameMapper.insertSelective(game);
    	if(retule > 0) {
    		return ResultUtil.success();
    	}else {
    		return ResultUtil.error(1, "保存失败，请稍后再试！");
    	}
    	
    	
    }
}

